package cn.wenhaha.app.config;

import cn.wenhaha.app.job.filter.LoginWebSocketFilter;
import cn.wenhaha.app.log.LogSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private LogSocketHandler logSocketHandler;
    @Resource
    private LoginWebSocketFilter loginWebSocketFilter;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(logSocketHandler, "/ws/system/log")
                .setAllowedOrigins("*")
                .addInterceptors(loginWebSocketFilter);

    }


}
